package phan.connection;

/**
 *
 * @author BAILLEURS SERVICES
 */
import java.sql.*;
import java.io.Serializable;
import phan.connection.DBLien;

public class ConnectionDB implements Serializable{

  private String login;
  private String password;
  private String hostname;
  private String port;
  private String nomDB;
  private Connection conx;

  public void setLogin(String valeur){
      this.login=valeur;
  }
  public void setPassword(String valeur){
      this.password=valeur;
  }
  public void setHostname(String valeur){
      this.hostname=valeur;
  }
  public void setNomDB(String valeur){
      this.nomDB=valeur;
  }
  public void setPort(String valeur){
      this.port=valeur;
  }

  public Connection getConnection(){
      if(Estconnect())
        return conx ;
      else
          return null;
  }
  private String construireUrl(){
      String url;
      url="jdbc:mysql://" +hostname+":"+port+"/"+nomDB;
      url=url+ "?user="+login+"&password="+password;
      return url;
  }

  private boolean Estconnect(){
      String url;
      boolean status=false;
      try{
            Class.forName("com.mysql.jdbc.Driver");
            url=construireUrl();
            conx=DriverManager.getConnection(url);
            status=true;
      }catch(Exception e){
          status=false;
          System.out.print(e);
      }
      return status;
  }
}















